package org.jacp.demo.ui.components;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JComponent;

public class GlassPanel extends JComponent implements MouseListener,
		MouseMotionListener {

	private int minX;
	private int minY;
	private int distanceX;
	private int distanceY;

	public GlassPanel() {
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
	}

	@Override
	protected void paintComponent(Graphics g) {
		Rectangle clip = g.getClipBounds();
		Color alphaWhite = new Color(1.0f, 1.0f, 1.0f, 0.65f);
		g.setColor(alphaWhite);
		g.fillRect(clip.x, clip.y, clip.width, clip.height);
	}

	@Override
	public void mouseClicked(MouseEvent e) {

	}

	@Override
	public void mousePressed(MouseEvent e) {
		minX = e.getX();
		minY = e.getY();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseDragged(MouseEvent e) {
		Graphics2D g2d = (Graphics2D) this.getGraphics();
		g2d.clearRect(minX, minY, distanceX, distanceY);
		distanceX = e.getX() - minX;
		distanceY = e.getY() - minY;
		g2d.setColor(Color.BLACK);

		g2d.drawRect(minX, minY, distanceX, distanceY);
		System.out.println(minX + ":" + minY + ":" + (distanceX) + ":"
				+ (distanceY));
		this.validate();

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
